<?php
class Candidate_language_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function get($data)
    {
    	$this->db->select('candidate_language.*, language.name AS languagename, language_level.name AS levelname');
    	$this->db->from('candidate_language');
    	$this->db->join('language', 'candidate_language.idlanguage = language.id', 'left');
    	$this->db->join('language_level', 'candidate_language.idlanguagelevel = language_level.id', 'left');
    	
    	if (isset($data['idcandidate'])) {
    		$this->db->where('idcandidate', $data['idcandidate']);
    	}
    	
    	if (isset($data['idlanguage']) && is_numeric($data['idlanguage'])) {
    		$this->db->where('candidate_language.id', $data['idlanguage']);
    	}
    	
    	if (isset($data['idlanguagetype']) && is_numeric($data['idlanguagetype'])) {
    		$this->db->where('candidate_language.idlanguage', $data['idlanguagetype']);
    	}
    	
    	$this->db->order_by('candidate_language.id');
    	
    	return $this->db->get();
    }
    
	function insert($data)
    {
    	$data_insert = array(
		   'idlanguage' => $data['idlanguagetype'],
		   'idlanguagelevel' => $data['idlanguagelevel'],
		   'idcandidate' => $data['idcandidate']
		);
		
		return $this->db->insert('candidate_language', $data_insert);
    }
    
	function update($data)
    {
    	$data_insert = array(
		  'idlanguage' => $data['idlanguagetype'],
		  'idlanguagelevel' => $data['idlanguagelevel']
		);
		
		$this->db->where('id', $data['idlanguage']);
		
		return $this->db->update('candidate_language', $data_insert);
    }
    
	function delete($data)
    {
    	$data_delete = array(
		   'id' => $data['id']
		);
		
		return $this->db->delete('candidate_language', $data_delete);
    }
}
?>